package com.zhxh.nzpos.setting;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.zhxh.nzpos.R;
import com.zhxh.nzpos.model.Member;
import com.zhxh.nzpos.sell.ItemDeleteCallback;
import com.zhxh.nzpos.setting.MemberSettingAdapter.ViewHolder;

public class OperatorListAdapter extends BaseAdapter {

	private ArrayList<Member> items;
	private LayoutInflater inflater;
	private ItemDeleteCallback deleteCallback;

	public OperatorListAdapter(LayoutInflater inflater,
			ArrayList<Member> dealItems, ItemDeleteCallback deleteCallback) {
		this.items = dealItems;
		this.inflater = inflater;
		this.deleteCallback = deleteCallback;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		//if (convertView == null) {
			convertView = inflater.inflate(R.layout.setting_operator_list_item,
					null);
			holder = new ViewHolder();
			holder.cardnumber = (TextView) convertView.findViewById(R.id.cardnumber);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.cardid = (TextView) convertView.findViewById(R.id.cardid);
			holder.phone = (TextView) convertView.findViewById(R.id.phone);
			holder.date = (TextView) convertView.findViewById(R.id.date);
			holder.points = (TextView) convertView.findViewById(R.id.points);
		/*	holder.deleteBtn = (Button) convertView
					.findViewById(R.id.operator_delete_btn);
			holder.deleteBtn.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (deleteCallback != null) {
						deleteCallback.onDelete(position);
					}
				}
			});*/
			convertView.setTag(holder);
		//} else {
		//	holder = (ViewHolder) convertView.getTag();
		//}

		Member item = items.get(position);
		if (item != null) {
			holder.cardnumber.setText(item.getCardNumber());
			holder.name.setText(item.getName());
			holder.cardid.setText(item.getShfzID());
			holder.date.setText(""+item.getModified());
			holder.phone.setText(""+item.getPhone());
			holder.points.setText(""+item.getPoints());
		//	holder.password.setText(item.getName());
		}
		return convertView;
	}

	static class ViewHolder {
		TextView cardnumber;
		TextView name;
		TextView cardid;
		TextView phone;
		TextView points;
		TextView date;
		Button deleteBtn;
	}
}
